<template>
  <div class="custom-table-list-wrapper">
    <div class="search" :class="{ active: toggleSearchStatus }">
      <div class="search-left" ref="searchFromRef">
        <el-form class="search-form" inline>
          <el-form-item label="分类">
            <el-select
              class="search-select"
              v-model="searchParams.type"
              placeholder="请选择"
              multiple
              :collapse-tags="true"
            >
              <el-option
                v-for="(item, index) of dict['user_type'].filter(
                  (i) => i.value !== '1' && i.value !== '5',
                )"
                :key="index"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="是否巡检人员">
            <el-select
              class="search-select"
              v-model="searchParams.isPatrol"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="(item, index) of dict['yn']"
                :key="index"
                :label="item.name"
                :value="Number(item.value)"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="关键词">
            <el-input
              class="search-input"
              v-model="searchParams.name"
              placeholder="请输入人员姓名、单位"
              :suffix-icon="Search"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
        <a
          class="search-left-toggle"
          v-if="showToggle"
          @click="handleToggleSearch"
        >
          <svg-icon :name="toggleSearchStatus ? 'up' : 'down'" />
          {{ toggleSearchStatus ? '收起' : '展开' }}
        </a>
      </div>
      <div class="search-right">
        <el-button type="primary" @click="initTableList(1)"
          ><svg-icon name="search" size="14px" />搜索</el-button
        >
        <el-button @click="handleResetCutsom"
          ><svg-icon name="reset" size="17px" />重置</el-button
        >
      </div>
    </div>
    <div class="content">
      <div class="content-table">
        <el-table class="custom-table" :data="tableData">
          <el-table-column type="index" label="序号" width="60px" />
          <el-table-column type="index" label="序号" width="60px" />
          <el-table-column prop="userName" label="真实姓名" />
          <el-table-column prop="loginName" label="手机号码/账号">
            <template #default="scope">
              {{
                scope.row.loginName.replace(
                  /^(\d{3})(\d{4})(\d{4})$/,
                  '$1****$3',
                )
              }}
            </template>
          </el-table-column>
          <el-table-column prop="unitContent" label="所属单位">
            <template #default="scope">
              {{ scope.row.unitName || scope.row.unitContent }}
            </template>
          </el-table-column>
          <el-table-column prop="visitRegionName" label="访问区域" />
          <el-table-column prop="mainPost" label="访问有效期">
            <template #default="scope">
              {{ moment(scope.row.visitStartTime).format('YYYY-MM-DD') }} -
              {{ moment(scope.row.visitEndTime).format('YYYY-MM-DD') }}
            </template>
          </el-table-column>
          <el-table-column prop="isPatrol" label="是否巡检人员">
            <template #default="scope">
              {{ getDictValue('yn', scope.row.isPatrol) }}
            </template>
          </el-table-column>
          <!-- <el-table-column label="操作" width="120px"> -->
          <el-table-column label="操作" width="80px">
            <template #default="scope">
              <el-button link type="primary" @click="handleDetail(scope.row)"
                >详情</el-button
              >
              <!-- <el-button link type="primary" @click="handleDetail(scope.row)"
                >轨迹</el-button
              > -->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="content-page">
        <el-pagination
          class="custom-pagination"
          :current-page="paginationParams.pageIndex"
          :page-size="paginationParams.pageSize"
          background
          :page-sizes="[10, 20, 30, 50]"
          layout="total, prev, pager, next, sizes, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="initTableList"
        />
      </div>
    </div>
    <DetailDialog
      ref="detailRef"
      :detail="currentDetail"
      @close="handleClose"
    />
  </div>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { useTableList } from '@/hooks/useTableList'
import DetailDialog from '@/views/manager/systemManage/user/detail.vue'
import FileList from '@/components/fileList/index.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import moment from 'moment'
import { useDict } from '@/hooks/useDict'
const { dict, getDictValue, getDictStyle } = useDict(['yn', 'user_type'])
import { getUserList } from '@/api/manager/systemManage/user.js'
const searchParams = ref({
  type: ['2', '3', '4'],
})
const {
  Search,
  toggleSearchStatus,
  showToggle,
  handleToggleSearch,
  tableData,
  paginationParams,
  total,
  initTableList,
  handleSizeChange,
  handleReset,
  handleDelete,
  addRef,
  detailRef,
  currentDetail,
  handleAdd,
  handleEdit,
  handleDetail,
  handleClose,
  searchFromRef,
} = useTableList(searchParams, getUserList)

const handleResetCutsom = () => {
  const params = { type: ['2', '3', '4'] }
  handleReset(params)
}
onMounted(() => {
  initTableList(1)
})
</script>
<style lang="scss" scoped>
@import '@/assets/styles/table.scss';
.popover-detail {
  width: 100%;
  .item {
    width: 100%;
    font-size: 14px;
    color: #757575;
    margin-bottom: 10px;
  }
}
.content-table {
  height: calc(100% - 50px);
}
</style>
